<?php
require_once 'Zend/Application/Resource/ResourceAbstract.php';
require_once 'Zend/Oauth/Consumer.php';
require_once 'Zend/Oauth/Token/Access.php';
require_once 'Zend/Oauth/Client.php';

class Core_Application_Resource_Twitter
	extends Zend_Application_Resource_ResourceAbstract
{
	/**
	 * The OAuth Consumer
	 * 
	 * @var array
	 */
	private $_consumer;
	
	/**
	 * The OAuth Server Client
	 * 
	 * @var array
	 */
	private $_serverClient;
	
	
	/**
	 * Defined by Zend_Application_Resource_Resource
	 *
	 * @return Object
	 */
	public function init()
	{
		$options = $this->getOptions();
		
		if ( isset($options['oauth']))
		{
			$this->_consumer = new Zend_Oauth_Consumer( $options['oauth'] );
		}
		
		if ( isset($options['server_token']))
		{
			$token = new Zend_Oauth_Token_Access();
			$token->setToken($options['server_token']['oauth_token']);
			$token->setTokenSecret($options['server_token']['oauth_secret']);
			
			$this->_serverClient = new Zend_Oauth_Client($options['oauth']);
	        $this->_serverClient->setToken($token);
		}
		
		return $this;
	}
	
	/**
	 * Retrieve an instance of the server client, if it exists.
	 */
	public function getServerClient() 
	{
		return $this->_serverClient;
	}
	
	/**
	 * Retrieve an instance of the configured oauth consumer.
	 */
	public function getOAuthConsumer()
	{
		return $this->_consumer;
	}
}